#include "GY_GraphicsReflection.h"

//!静态成员变量必须在类外初始化
GY_GraphicsReflection* GY_GraphicsReflection::m_pGraphicsReflection = nullptr;

GY_GraphicsReflection::GY_GraphicsReflection(QObject *parent) : QObject(parent)
{
    m_pReflectionClass = new GY_ReflectionClass;
    initRegisterObject();
}

GY_GraphicsReflection* GY_GraphicsReflection::getInstance(QObject *parent)
{
    if(m_pGraphicsReflection == nullptr) {
        m_pGraphicsReflection = new GY_GraphicsReflection(parent);
    }
    return m_pGraphicsReflection;
}

void GY_GraphicsReflection::release()
{
    if(m_pGraphicsReflection != nullptr) {
        delete m_pGraphicsReflection;
        m_pGraphicsReflection = nullptr;
    }
}

void GY_GraphicsReflection::initRegisterObject()
{
    //GraphicalObject
    m_pReflectionClass->registerClass<GY_ObjectGroup>("GraphicObject");

    //BasicGroups
    m_pReflectionClass->registerClass<GY_AttributesGroup>("AttributesGroup"); //设置全属性组件
    m_pReflectionClass->registerClass<GY_ClippingRegion>("ClippingRegion"); //拖动显示组件
    m_pReflectionClass->registerClass<GY_MutuallyExclusiveGroup>("MutuallyExclusiveGroup"); //组件
    m_pReflectionClass->registerClass<GY_SimpleGroup>("SimpleGroup"); //简单组件
    m_pReflectionClass->registerClass<GY_StencilGroup>("StencilGroup"); //交叉显示组件
    m_pReflectionClass->registerClass<GY_TransformGroup>("TransformGroup"); //选转组件
    m_pReflectionClass->registerClass<GY_ClippingToolContainer>("ClippingToolContainer"); //剪切工具组件
    m_pReflectionClass->registerClass<GY_RepeatGroup>("RepeatGroup"); //复制组件
    m_pReflectionClass->registerClass<GY_ScaleToFitGroup>("ScaleToFitGroup"); //伸缩组

    //GraphicPrimitives
    m_pReflectionClass->registerClass<GY_GraphicsArcItem>("Arc"); //扇形
    m_pReflectionClass->registerClass<GY_GraphicsBezierItem>("Bezier"); //贝塞尔曲线
    m_pReflectionClass->registerClass<GY_GraphicsCircleItem>("Circle"); //圆
    m_pReflectionClass->registerClass<GY_GraphicsCornerStyleRectItem>("CornerStyleRect"); //角型矩形
    m_pReflectionClass->registerClass<GY_GraphicsCrown>("Crown"); //环形
    m_pReflectionClass->registerClass<GY_GraphicsEllipseItem>("Ellipse"); //椭圆
    m_pReflectionClass->registerClass<GY_GraphicsFillet>("Fillet"); //圆角矩形
//    m_pReflectionClass->registerClass<GY_GraphicsImage>("Image"); //图片
    m_pReflectionClass->registerClass<GY_GraphicsLineItem>("Line"); //线条
    m_pReflectionClass->registerClass<GY_GraphicsLinearTick>("LinearTicks"); //线形刻度
    m_pReflectionClass->registerClass<GY_GraphicsPolygon>("Polygon");//多边形
    m_pReflectionClass->registerClass<GY_GraphicsPolygonRegular>("PolygonRegular");//正多边形
    m_pReflectionClass->registerClass<GY_GraphicsPolyline>("Polyline");//多边线
    m_pReflectionClass->registerClass<GY_GraphicsRectItem>("Rect2Pnt"); //矩形
    m_pReflectionClass->registerClass<GY_GraphicsRotTick>("RotTicks"); //弧形刻度
    m_pReflectionClass->registerClass<GY_GraphicsWideTextItem>("Text"); //文本
    m_pReflectionClass->registerClass<GY_GraphicsWideTextItem>("WideText"); //文本
    m_pReflectionClass->registerClass<GY_GraphicsWideTextItem>("TextInput"); //文本输入
    m_pReflectionClass->registerClass<GY_GraphicsWideTextItem>("WideTextInput"); //文本输入
    m_pReflectionClass->registerClass<GY_GraphicsRectWidthHeightItem>("RectWidthHeight"); //长宽矩形(重写版)
    //DeviceInput暂时放在基础控件里面
    m_pReflectionClass->registerClass<GY_RectActiveArea>("RectActiveArea"); //矩形激活区域
    m_pReflectionClass->registerClass<GY_PolarActiveArea>("PolarActiveArea"); //扇形激活区域

    //InputObjects
    m_pReflectionClass->registerClass<GY_KnobFinite>("KnobFinite"); //半角按钮
    m_pReflectionClass->registerClass<GY_ButtonItem>("Button"); //按钮(重写版)
    m_pReflectionClass->registerClass<GY_Switch>("Switch"); //开关

    //OutputObjects
    m_pReflectionClass->registerClass<GY_ADI>("ADI"); //蒙版
    m_pReflectionClass->registerClass<GY_BarChartHoriz>("BarChartHoriz"); //水平柱状条
    m_pReflectionClass->registerClass<GY_BarChartVert>("BarChartVert"); //垂直柱状条
    m_pReflectionClass->registerClass<GY_DialCircular>("DialCircular"); //全方位指针
    m_pReflectionClass->registerClass<GY_DialFinite>("DialFinite"); //半方位指针
    m_pReflectionClass->registerClass<GY_TapeCircular>("TapeCircular"); //尺标
    m_pReflectionClass->registerClass<GY_TapeFinite>("TapeFinite"); //半尺标
    m_pReflectionClass->registerClass<GY_Scale>("Scale"); //进度指示器

    //DataObjects
    m_pReflectionClass->registerClass<GY_BoolData>("BoolData"); //bool数据
    m_pReflectionClass->registerClass<GY_ColorData>("ColorData"); //color数据
    m_pReflectionClass->registerClass<GY_CoordData>("CoorData"); //coord数据
    m_pReflectionClass->registerClass<GY_FloatData>("FloatData"); //float数据
    m_pReflectionClass->registerClass<GY_DoubleData>("DoubleData"); //double数据
    m_pReflectionClass->registerClass<GY_IntData>("IntData"); //int数据
    m_pReflectionClass->registerClass<GY_StringData>("StringData"); //string数据
    m_pReflectionClass->registerClass<GY_ColorArray>("ColorArray"); //color数组
    m_pReflectionClass->registerClass<GY_DoubleArray>("DoubleArray"); //double数组
    m_pReflectionClass->registerClass<GY_CoordArray>("CoordArray"); //coord数组
    m_pReflectionClass->registerClass<GY_FloatArray>("FloatArray"); //float数组
    m_pReflectionClass->registerClass<GY_IntArray>("IntArray"); //int数组
    m_pReflectionClass->registerClass<GY_StringArray>("StringArray"); //string数组

    //Calculators
    m_pReflectionClass->registerClass<GY_FormatFloat>("FormatFloat"); //float转换字符串函数
    m_pReflectionClass->registerClass<GY_FormatDouble>("FormatDouble"); //double转换字符串函数
    m_pReflectionClass->registerClass<GY_Timer>("Timer"); //timer计时器
    m_pReflectionClass->registerClass<GY_SignalGenerator>("SignalGenerator"); //SignalGenerator信号发生器
    m_pReflectionClass->registerClass<GY_ConcatStrings>("ConcatStrings"); //ConcatStrings字符串拼接
    m_pReflectionClass->registerClass<GY_SystemClock>("SystemClock"); //SystemClock实时日期时间
    m_pReflectionClass->registerClass<GY_ConcatWStrings>("ConcatWStrings"); //ConcatWStrings字符串拼接

    //UIComponents
    m_pReflectionClass->registerClass<GY_Bezel>("Bezel"); //Bezel UI按钮

}

void GY_GraphicsReflection::registerObjectClass(const QString &className)
{
    m_pReflectionClass->registerClass<GY_ObjectGroup>(className); //注册组件
}

QObject *GY_GraphicsReflection::newInstanceObjectClass(const QByteArray &className, const QString &guid)
{
    return m_pReflectionClass->newInstance(className, Q_ARG(QString,guid));
}
